package hz.mobileproject.pda.firesafety.adapter;

import android.content.Context;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.blankj.utilcode.util.StringUtils;

import org.xutils.view.annotation.ViewInject;

import java.util.List;

import hz.mobileproject.pda.R;
import hz.mobileproject.pda.firesafety.bean.FireSafetyThingBean;
import hz.mobileproject.pda.firesafety.bean.Rp_queryfire;
import hz.mobileproject.pda.ui.base.BaseCustomAdapter;
import hz.mobileproject.pda.ui.view.PhotoDialog;

/**
 * Created by Lc on 2018/2/28.
 */

public class StartFireAdapter extends BaseCustomAdapter<Rp_queryfire,StartFireAdapter.ViewHolder> {


    public StartFireAdapter(Context mContext, List<Rp_queryfire> list) {
        super(mContext, list);
    }

    @Override
    protected int bindView() {
        return R.layout.fire_safety_list_item;
    }

    @Override
    protected ViewHolder createViewHolder() {
        return new ViewHolder();
    }

    @Override
    protected void bindData(final int i, View convertView, ViewHolder vh) {
        vh.tvBoxName.setText(mList.get(i).getBox_name());
        vh.tvAssetCode.setText(mList.get(i).getAsset_code());
        vh.tvCode.setText(mList.get(i).getCode());
        vh.tvName.setText(mList.get(i).getName());
        vh.tvPurchaseDate.setText(mList.get(i).getPurchase_date());
        vh.tvProduceDate.setText(mList.get(i).getProduce_date());
        vh.tvExpiredDate.setText(mList.get(i).getExpired_date());
        vh.tvChangeDate.setText(mList.get(i).getChange_date());
        vh.tvDeptId.setText(mList.get(i).getDept_id());
        vh.tvDeptName.setText(mList.get(i).getDept_name());
        if(StringUtils.isEmpty(mList.get(i).getImage_url())){
            vh.llImage.setVisibility(View.GONE);
        }else {
            vh.llImage.setVisibility(View.VISIBLE);
            vh.tvImageUrl.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    //查看图片
                    PhotoDialog dialog = new PhotoDialog(mContext, mList.get(i).getImage_url());
                    dialog.show();
                }
            });
        }
    }

    class ViewHolder{
        @ViewInject(R.id.tv_fire_item_box_name)
        TextView tvBoxName;
        @ViewInject(R.id.tv_fire_item_name)
        TextView tvName;
        @ViewInject(R.id.tv_fire_item_asset_code)
        TextView tvAssetCode;
        @ViewInject(R.id.tv_fire_item_code)
        TextView tvCode;
        @ViewInject(R.id.tv_fire_item_purchase_date)
        TextView tvPurchaseDate;
        @ViewInject(R.id.tv_fire_item_produce_date)
        TextView tvProduceDate;
        @ViewInject(R.id.tv_fire_item_expired_date)
        TextView tvExpiredDate;
        @ViewInject(R.id.tv_fire_item_change_date)
        TextView tvChangeDate;
        @ViewInject(R.id.tv_fire_item_dept_id)
        TextView tvDeptId;
        @ViewInject(R.id.tv_fire_item_dept_name)
        TextView tvDeptName;
        @ViewInject(R.id.tv_fire_item_image_url)
        TextView tvImageUrl;
        @ViewInject(R.id.ll_fire_item_image)
        LinearLayout llImage;
    }
}
